package day19.zhiyou100;

// 测试类
class TestPeopleThread {
    public static void main(String[] args) {
        CountryThread countryThread = new CountryThread("国家");
        PeopleThread people = new PeopleThread("路人甲");

        countryThread.setDaemon(true);
        countryThread.start();
        people.start();
    }
}


// Country
class CountryThread extends Thread {

    public CountryThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        while (true) {// 死循环
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(this.getName() + "保护着你。。。");
        }
        //System.out.println("国家也over了");
    }
}


public class PeopleThread extends Thread{

    public PeopleThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        // 你活300天
        for (int i = 1; i <= 300; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(this.getName() + "活着，这是第"+i+"天");
        }
        System.out.println("我over了。。。。。");
    }
}
